<template>
	<view>
		<!-- 头部header -->
		<view class="header">
			<uni-nav-bar :statusBar="true" leftIcon="arrowleft" fixed="true" title="食堂公示" @clickLeft="clickLeft"></uni-nav-bar>
		</view>
		<!-- 食堂公示 -->
		<view class="single" v-for="(item,index) in foodList" :key="index" @click="jumpPage_cl(item.canteenPublicityId)">
			<text class="name">{{item.title}}</text>
			<text class="time">{{item.createTime}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				foodList: [],
				contractorId: '',
				departmentId: '',
				currentPage: 1,
				pageSize: 10
			}
		},
		onShow() {
			
			uni.getStorage({
				key: 'contractorId',
				success: (e) => {
					this.contractorId = e.data
				}

			}) 
			uni.getStorage({
				key: 'departmentId',
				success: (e) => {
					this.departmentId = e.data
				}

			})
			this.loadmore()
		},
		onPullDownRefresh() {
			this.loadmore()
		},
		onReachBottom() {
			this.loadmore('more')
		},
		methods: {
			/**
			 * @description: 加载更多公示
			 * @author: LinW (xuebingchuan_20@163.com)
			 * @createDate: 2020-10-10 10:40
			 */
			loadmore(str) {
				if (str === 'more') {
					let params = {
						page: this.currentPage + 1,
						pageSize: this.pageSize,
						departmentId: this.departmentId,
						orgId: this.contractorId
					}
					this.$request.ygstCanteenListGet(params).then(res => {
						this.foodList.push(...res.list)
						uni.stopPullDownRefresh()
					})
				} else {
					let params = {
						page: this.currentPage,
						pageSize: this.pageSize,
						departmentId: this.departmentId,
						orgId: this.contractorId
					}
					this.$request.ygstCanteenListGet(params).then(res => {
						this.foodList = res.list
						uni.stopPullDownRefresh()
					})
				}

			},
			/**
			 * @description: 跳转公示详情页
			 * @author: LinW (xuebingchuan_20@163.com)
			 * @createDate: 2020-10-10 10:40
			 */
			jumpPage_cl(canteenPublicityId) {
				uni.navigateTo({
					url: `./foodAdvertisingDetail/foodAdvertisingDetail?id=${canteenPublicityId}`
				})
			},
			/**
			 * @description: 返回上一页
			 * @author: LinW (xuebingchuan_20@163.com)
			 * @createDate: 2020-10-10 10:40
			 */
			clickLeft() {
				uni.navigateBack()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.single {
		display: flex;
		flex-direction: column;
		padding-left: 20rpx;
		border-bottom: 1px solid #CCCCCC;

		.name {}

		.time {
			font-size: 12rpx;
			color: #CCCCCC;
		}
	}
</style>
